package com.pie4cloud.pie.jpa.id;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.pie4cloud.pie.jpa.util.SpringUtil;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;

import java.io.Serializable;
import java.util.Properties;

public class GenerateSnowflakeId implements IdentifierGenerator, Configurable {


	@Override
	public void configure(Type type, Properties properties, ServiceRegistry serviceRegistry) throws MappingException {

	}

	@Override
	public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
		Snowflake snowflake= IdUtil.getSnowflake();
		return snowflake.nextId();
	}
}